﻿@using ExamplesCommonCode.CommonAdmin
@model ExamplesCommonCode.CommonAdmin.RoleCreateUpdateDto

<table class="table">
    <thead>
    <tr>
        <th>
            Group
        </th>
        <th>
            Description
        </th>
        <th>
            Permission
        </th>
        <th>Selected?</th>
    </tr>
    </thead>
    <tbody id="permission-selection">
    @for (int i = 0; i < Model.PermissionsWithSelect.Count; i++)
    {
        <tr>
            <td>
                @Model.PermissionsWithSelect[i].GroupName
            </td>
            <td>
                @Model.PermissionsWithSelect[i].Description
            </td>
            <td>
                @Model.PermissionsWithSelect[i].PermissionName
                @Html.Hidden($"{nameof(RoleCreateUpdateDto.PermissionsWithSelect)}[{i}].{nameof(PermissionInfoWithSelectDto.PermissionName)}",
                    Model.PermissionsWithSelect[i].PermissionName)
            </td>
            <td>
                @Html.Hidden($"{nameof(RoleCreateUpdateDto.PermissionsWithSelect)}[{i}].{nameof(PermissionInfoWithSelectDto.Selected)}",
                    @Model.PermissionsWithSelect[i].Selected,
                    new { id = Model.PermissionsWithSelect[i].PermissionName})
                <button type="button" class='btn-sm  @(Model.PermissionsWithSelect[i].Selected ? "btn-primary" : "btn-secondary")'
                        onclick="TogglePermissionSelect(this, '@Model.PermissionsWithSelect[i].PermissionName')">
                    @(Model.PermissionsWithSelect[i].Selected ? "Selected" : "Select")
                </button>
            </td>
        </tr>
    }
    </tbody>
</table>


